
package com.scalar.chiptrack.marketing.actions;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.process.dao.FinishedGoodsDAO;


/**
 * Implementation of <strong>Action</strong> that gives customers list,
 * search with customer name, create sales order
 *
 * @author Kesava Kumar Achanala
 * @version $Revision: 1.1.1.1 $ $Date: 2006/12/11 23:43:04 $
 */

public final class ProductsAction extends ChipTrackAction {


    // ----------------------------------------------------- Instance Variables
   

    // --------------------------------------------------------- Public Methods


    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param actionForm The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     *
     * @exception Exception if business logic throws an exception
     */
    public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws Exception {

        HttpSession session = request.getSession();
        if( session.getAttribute( SessionKeys.USER_KEY ) == null ) 
        {
            return( mapping.findForward ("login") );
        }
        
        boolean success = false;
        
        HashMap errors = new HashMap();
        request.setAttribute( SessionKeys.ERROR_MESSAGES, errors );
 
        // Balaram on July 31, 2003
        try
        {
            ArrayList productsList = FinishedGoodsDAO.loadAllFinishedGoods();
            request.setAttribute( "finishedGoodsList", productsList );
            
            success = true;
        }
        catch( Exception e )
        {
            e.printStackTrace();
            
            errors.put( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_LOADING_ALL_FINISHED_GOODS );
            errors.put( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
            session.setAttribute( SessionKeys.ERROR_REPORT_SUBJECT, ERROR_IN_LOADING_ALL_FINISHED_GOODS );
            session.setAttribute( SessionKeys.ERROR_REPORT, e );
        }
        
        //Please look at this return later(Where do we need this retrurned) ????
        return (mapping.findForward("success"));

    }

}
